﻿using System.Data;
using System;

namespace eDoc.DAL
{
    /// <summary>
    /// 
    /// </summary>
    public class StoredProcedures : StoredProcedures_Base
    {

        private MainDB _db;

        public StoredProcedures(MainDB db)
            : base(db)
        {
            _db = db;
        }
        #region

        /// <summary>
        /// Insert thong tin cua ung dung
        /// </summary>
        /// <param name="AppKey">Key tu sinh cua ung dung</param>
        /// <param name="AppName">Ten ung dung</param>
        /// <param name="AppVersion">Phien ban cua ung dung</param>
        /// <param name="AppBundleIdentifier">Bundle Identifier</param>
        /// <param name="AppDeviceFamily">Device Family</param>
        /// <param name="AppMinimumOSVersion">Minimum OS Version</param>
        /// <param name="AppSize">Size</param>
        /// <param name="AppPlistPath">Duong dan file plist</param>
        /// <param name="AppUrlInstall">Duong dan file ipa de install</param>
        /// <param name="AppCFBundleSignature">Chu ky cua ung dung</param>
        /// <param name="AppIcon">Icon cua ung dung</param>
        public void VNA_Insert_AppPlist(string AppKey, string AppName, string AppVersion, string AppBundleIdentifier, string AppDeviceFamily, string AppMinimumOSVersion, int AppSize, string AppPlistPath, string AppUrlInstall, string AppCFBundleSignature, string AppIcon)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Insert_AppPlist", true);
            _db.AddParameter(cmd, "AppKey", DbType.String, AppKey);
            _db.AddParameter(cmd, "AppName", DbType.String, AppName);
            _db.AddParameter(cmd, "AppVersion", DbType.String, AppVersion);
            _db.AddParameter(cmd, "AppBundleIdentifier", DbType.String, AppBundleIdentifier);
            _db.AddParameter(cmd, "AppDeviceFamily", DbType.String, AppDeviceFamily);
            _db.AddParameter(cmd, "AppMinimumOSVersion", DbType.String, AppMinimumOSVersion);
            _db.AddParameter(cmd, "AppSize", DbType.Int32, AppSize);
            _db.AddParameter(cmd, "AppPlistPath", DbType.String, AppPlistPath);
            _db.AddParameter(cmd, "AppUrlInstall", DbType.String, AppUrlInstall);
            _db.AddParameter(cmd, "AppCFBundleSignature", DbType.String, AppCFBundleSignature);
            _db.AddParameter(cmd, "AppIcon", DbType.String, AppIcon);
            CreateDataTable(cmd);
           
        }

        /// <summary>
        /// Insert thong tin cua ung dung
        /// </summary>
        /// <param name="AppKey">Key tu sinh cua ung dung</param>
        /// <param name="AppName">Ten ung dung</param>
        /// <param name="AppDisplayName">Ten hien thi ung dung</param>
        /// <param name="AppVersion">Phien ban cua ung dung</param>
        /// <param name="AppBundleIdentifier">Bundle Identifier</param>
        /// <param name="AppDeviceFamily">Device Family</param>
        /// <param name="AppMinimumOSVersion">Minimum OS Version</param>
        /// <param name="AppSize">Size</param>
        /// <param name="AppPlistPath">Duong dan file plist</param>
        /// <param name="AppUrlInstall">Duong dan file ipa de install</param>
        /// <param name="AppCFBundleSignature">Chu ky cua ung dung</param>
        /// <param name="AppIcon">Icon cua ung dung</param>
        /// <param name="BuildTime">Thoi gian build ung dung</param>
        /// <param name="AppMode">Loai ung dung duoc su dung thoe nhan vien</param>
        /// <param name="AppDesc">Mo ta ung dung</param>
        /// <param name="Published">Trang thai : published hay testing</param>
        /// <param name="AppJB">Ung dung Jailbreak</param>
        /// <param name="AppPlatformVersion">Xac dinh version hien tai cua ung dung co cai dc tren may hay ko</param>
        /// <param name="AppPlatformName">Platform Name</param>
        public void VNA_Insert_AppPlist(string AppKey, string AppName, string AppDisplayName, string AppVersion, string AppBundleIdentifier, string AppDeviceFamily, string AppMinimumOSVersion, int AppSize, string AppPlistPath, string AppUrlInstall, string AppCFBundleSignature, string AppIcon, DateTime BuildTime, int AppMode, string AppDesc, bool Published, bool AppJB, string AppPlatformVersion,  string AppPlatformName)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Insert_AppPlist", true);
            _db.AddParameter(cmd, "AppKey", DbType.String, AppKey);
            _db.AddParameter(cmd, "AppName", DbType.String, AppName);
            _db.AddParameter(cmd, "AppDisplayName", DbType.String, AppDisplayName);
            _db.AddParameter(cmd, "AppVersion", DbType.String, AppVersion);
            _db.AddParameter(cmd, "AppBundleIdentifier", DbType.String, AppBundleIdentifier);
            _db.AddParameter(cmd, "AppDeviceFamily", DbType.String, AppDeviceFamily);
            _db.AddParameter(cmd, "AppMinimumOSVersion", DbType.String, AppMinimumOSVersion);
            _db.AddParameter(cmd, "AppSize", DbType.Int32, AppSize);
            _db.AddParameter(cmd, "AppPlistPath", DbType.String, AppPlistPath);
            _db.AddParameter(cmd, "AppUrlInstall", DbType.String, AppUrlInstall);
            _db.AddParameter(cmd, "AppCFBundleSignature", DbType.String, AppCFBundleSignature);
            _db.AddParameter(cmd, "AppIcon", DbType.String, AppIcon);
            _db.AddParameter(cmd, "BuildTime", DbType.DateTime, BuildTime);
            _db.AddParameter(cmd, "AppMode", DbType.Int32, AppMode);
            _db.AddParameter(cmd, "AppDesc", DbType.String, AppDesc);
            _db.AddParameter(cmd, "Published", DbType.Boolean, Published);
            _db.AddParameter(cmd, "AppJB", DbType.Boolean, AppJB);
            _db.AddParameter(cmd, "AppPlatformVersion", DbType.String, AppPlatformVersion);
            _db.AddParameter(cmd, "AppPlatformName", DbType.String, AppPlatformName);
            CreateDataTable(cmd);

        }

        /// <summary>
        /// Insert thong tin cua ung dung
        /// </summary>
        /// <param name="AppKey">Key tu sinh cua ung dung</param>
        /// <param name="AppName">Ten ung dung</param>
        /// <param name="AppDisplayName">Ten hien thi ung dung</param>
        /// <param name="AppVersion">Phien ban cua ung dung</param>
        /// <param name="AppBundleIdentifier">Bundle Identifier</param>
        /// <param name="AppDeviceFamily">Device Family</param>
        /// <param name="AppMinimumOSVersion">Minimum OS Version</param>
        /// <param name="AppSize">Size</param>
        /// <param name="AppPlistPath">Duong dan file plist</param>
        /// <param name="AppUrlInstall">Duong dan file ipa de install</param>
        /// <param name="AppCFBundleSignature">Chu ky cua ung dung</param>
        /// <param name="AppIcon">Icon cua ung dung</param>
        /// <param name="BuildTime">Thoi gian build ung dung</param>
        /// <param name="AppMode">Loai ung dung duoc su dung thoe nhan vien</param>
        /// <param name="AppDesc">Mo ta ung dung</param>
        /// <param name="Published">Trang thai : published hay testing</param>
        /// <param name="AppJB">Ung dung Jailbreak</param>
        /// <param name="AppPlatformVersion">Xac dinh version hien tai cua ung dung co cai dc tren may hay ko</param>
        /// <param name="AppPlatformName">Platform Name</param>
        /// <param name="ExpirationDate">Thoi gian het han ung dung</param>
        public void VNA_Insert_AppPlist(string AppKey, string AppName, string AppDisplayName, string AppVersion, string AppBundleIdentifier, 
                                        string AppDeviceFamily, string AppMinimumOSVersion, int AppSize, string AppPlistPath, string AppUrlInstall, 
                                        string AppCFBundleSignature, string AppIcon, DateTime BuildTime, int AppMode, string AppDesc, bool Published,
                                        bool AppJB, string AppPlatformVersion, string AppPlatformName, DateTime ExpirationDate, string AppPlistContent)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Insert_AppPlist", true);
            _db.AddParameter(cmd, "AppKey", DbType.String, AppKey);
            _db.AddParameter(cmd, "AppName", DbType.String, AppName);
            _db.AddParameter(cmd, "AppDisplayName", DbType.String, AppDisplayName);
            _db.AddParameter(cmd, "AppVersion", DbType.String, AppVersion);
            _db.AddParameter(cmd, "AppBundleIdentifier", DbType.String, AppBundleIdentifier);
            _db.AddParameter(cmd, "AppDeviceFamily", DbType.String, AppDeviceFamily);
            _db.AddParameter(cmd, "AppMinimumOSVersion", DbType.String, AppMinimumOSVersion);
            _db.AddParameter(cmd, "AppSize", DbType.Int32, AppSize);
            _db.AddParameter(cmd, "AppPlistPath", DbType.String, AppPlistPath);
            _db.AddParameter(cmd, "AppUrlInstall", DbType.String, AppUrlInstall);
            _db.AddParameter(cmd, "AppCFBundleSignature", DbType.String, AppCFBundleSignature);
            _db.AddParameter(cmd, "AppIcon", DbType.String, AppIcon);
            _db.AddParameter(cmd, "BuildTime", DbType.DateTime, BuildTime);
            _db.AddParameter(cmd, "AppMode", DbType.Int32, AppMode);
            _db.AddParameter(cmd, "AppDesc", DbType.String, AppDesc);
            _db.AddParameter(cmd, "Published", DbType.Boolean, Published);
            _db.AddParameter(cmd, "AppJB", DbType.Boolean, AppJB);
            _db.AddParameter(cmd, "AppPlatformVersion", DbType.String, AppPlatformVersion);
            _db.AddParameter(cmd, "AppPlatformName", DbType.String, AppPlatformName);
            _db.AddParameter(cmd, "ExpirationDate", DbType.DateTime, ExpirationDate);
            _db.AddParameter(cmd, "AppPlistContent", DbType.String, AppPlistContent);
            CreateDataTable(cmd);

        }

        /// <summary>
        /// Insert thong tin cua ung dung
        /// </summary>
        /// <param name="AppKey">Key tu sinh cua ung dung</param>
        /// <param name="AppName">Ten ung dung</param>
        /// <param name="AppVersion">Phien ban cua ung dung</param>
        /// <param name="AppBundleIdentifier">Bundle Identifier</param>
        /// <param name="AppDeviceFamily">Device Family</param>
        /// <param name="AppMinimumOSVersion">Minimum OS Version</param>
        /// <param name="AppSize">Size</param>
        /// <param name="AppPlistPath">Duong dan file plist</param>
        /// <param name="AppUrlInstall">Duong dan file ipa de install</param>
        /// <param name="AppCFBundleSignature">Chu ky cua ung dung</param>
        /// <param name="AppIcon">Icon cua ung dung</param>
        /// <param name="BuildTime">Thoi gian build ung dung</param>
        public void VNA_Insert_AppPlist(string AppKey, string AppName, string AppVersion, string AppBundleIdentifier, string AppDeviceFamily, string AppMinimumOSVersion, int AppSize, string AppPlistPath, string AppUrlInstall, string AppCFBundleSignature, string AppIcon, DateTime BuildTime)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Insert_AppPlist", true);
            _db.AddParameter(cmd, "AppKey", DbType.String, AppKey);
            _db.AddParameter(cmd, "AppName", DbType.String, AppName);
            _db.AddParameter(cmd, "AppVersion", DbType.String, AppVersion);
            _db.AddParameter(cmd, "AppBundleIdentifier", DbType.String, AppBundleIdentifier);
            _db.AddParameter(cmd, "AppDeviceFamily", DbType.String, AppDeviceFamily);
            _db.AddParameter(cmd, "AppMinimumOSVersion", DbType.String, AppMinimumOSVersion);
            _db.AddParameter(cmd, "AppSize", DbType.Int32, AppSize);
            _db.AddParameter(cmd, "AppPlistPath", DbType.String, AppPlistPath);
            _db.AddParameter(cmd, "AppUrlInstall", DbType.String, AppUrlInstall);
            _db.AddParameter(cmd, "AppCFBundleSignature", DbType.String, AppCFBundleSignature);
            _db.AddParameter(cmd, "AppIcon", DbType.String, AppIcon);
            _db.AddParameter(cmd, "BuildTime", DbType.DateTime, BuildTime);
            CreateDataTable(cmd);

        }

        /// <summary>
        /// Update thong tin cua ung dung
        /// </summary>
        /// <param name="ID">ID cua ung dung</param>
        /// <param name="AppKey">Key tu sinh cua ung dung</param>
        /// <param name="AppName">Ten ung dung</param>
        /// <param name="AppVersion">Phien ban cua ung dung</param>
        /// <param name="AppBundleIdentifier">Bundle Identifier</param>
        /// <param name="AppDeviceFamily">Device Family</param>
        /// <param name="AppMinimumOSVersion">Minimum OS Version</param>
        /// <param name="AppSize">Size</param>
        /// <param name="AppPlistPath">Duong dan file plist</param>
        /// <param name="AppUrlInstall">Duong dan file ipa de install</param>
        /// <param name="AppCFBundleSignature">Chu ky cua ung dung</param>
        /// <param name="AppIcon">Icon cua ung dung</param>
        /// <param name="Published">Published hay Testing</param>
        public void VNA_Update_AppPlist(int ID, string AppKey, string AppName, string AppVersion, string AppBundleIdentifier, string AppDeviceFamily, string AppMinimumOSVersion, int AppSize, string AppPlistPath, string AppUrlInstall, string AppCFBundleSignature, string AppIcon, bool Published)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Update_AppPlist", true);
            _db.AddParameter(cmd, "ID", DbType.Int32, ID);
            _db.AddParameter(cmd, "AppKey", DbType.String, AppKey);
            _db.AddParameter(cmd, "AppName", DbType.String, AppName);
            _db.AddParameter(cmd, "AppVersion", DbType.String, AppVersion);
            _db.AddParameter(cmd, "AppBundleIdentifier", DbType.String, AppBundleIdentifier);
            _db.AddParameter(cmd, "AppDeviceFamily", DbType.String, AppDeviceFamily);
            _db.AddParameter(cmd, "AppMinimumOSVersion", DbType.String, AppMinimumOSVersion);
            _db.AddParameter(cmd, "AppSize", DbType.Int32, AppSize);
            _db.AddParameter(cmd, "AppPlistPath", DbType.String, AppPlistPath);
            _db.AddParameter(cmd, "AppUrlInstall", DbType.String, AppUrlInstall);
            _db.AddParameter(cmd, "AppCFBundleSignature", DbType.String, AppCFBundleSignature);
            _db.AddParameter(cmd, "AppIcon", DbType.String, AppIcon);
            _db.AddParameter(cmd, "Published", DbType.Boolean, Published);
            CreateDataTable(cmd);

        }

        /// <summary>
        /// Update thong tin cua ung dung
        /// </summary>
        /// <param name="ID">ID cua ung dung</param>
        /// <param name="AppKey">Key tu sinh cua ung dung</param>
        /// <param name="AppName">Ten ung dung</param>
        /// <param name="AppDisplayName">Ten hien thi ung dung</param>
        /// <param name="AppVersion">Phien ban cua ung dung</param>
        /// <param name="AppBundleIdentifier">Bundle Identifier</param>
        /// <param name="AppDeviceFamily">Device Family</param>
        /// <param name="AppMinimumOSVersion">Minimum OS Version</param>
        /// <param name="AppSize">Size</param>
        /// <param name="AppPlistPath">Duong dan file plist</param>
        /// <param name="AppUrlInstall">Duong dan file ipa de install</param>
        /// <param name="AppCFBundleSignature">Chu ky cua ung dung</param>
        /// <param name="AppIcon">Icon cua ung dung</param>
        /// <param name="Published">Published hay Testing</param>
        /// <param name="AppMode">Loai ung dung tuy thuoc theo nhan vien</param>
        /// <param name="AppDesc">Mo ta ung dung</param>
        /// <param name="AppJB">Ung dung Jailbreak</param>
        public void VNA_Update_AppPlist(int ID, string AppKey, string AppName, string AppDisplayName, string AppVersion, string AppBundleIdentifier, string AppDeviceFamily, string AppMinimumOSVersion, int AppSize, string AppPlistPath, string AppUrlInstall, string AppCFBundleSignature, string AppIcon, bool Published, int AppMode, string AppDesc, bool AppJB)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Update_AppPlist", true);
            _db.AddParameter(cmd, "ID", DbType.Int32, ID);
            _db.AddParameter(cmd, "AppKey", DbType.String, AppKey);
            _db.AddParameter(cmd, "AppName", DbType.String, AppName);
            _db.AddParameter(cmd, "AppDisplayName", DbType.String, AppDisplayName);
            _db.AddParameter(cmd, "AppVersion", DbType.String, AppVersion);
            _db.AddParameter(cmd, "AppBundleIdentifier", DbType.String, AppBundleIdentifier);
            _db.AddParameter(cmd, "AppDeviceFamily", DbType.String, AppDeviceFamily);
            _db.AddParameter(cmd, "AppMinimumOSVersion", DbType.String, AppMinimumOSVersion);
            _db.AddParameter(cmd, "AppSize", DbType.Int32, AppSize);
            _db.AddParameter(cmd, "AppPlistPath", DbType.String, AppPlistPath);
            _db.AddParameter(cmd, "AppUrlInstall", DbType.String, AppUrlInstall);
            _db.AddParameter(cmd, "AppCFBundleSignature", DbType.String, AppCFBundleSignature);
            _db.AddParameter(cmd, "AppIcon", DbType.String, AppIcon);
            _db.AddParameter(cmd, "Published", DbType.Boolean, Published);
            _db.AddParameter(cmd, "AppMode", DbType.Int32, AppMode);
            _db.AddParameter(cmd, "AppDesc", DbType.String, AppDesc);
            _db.AddParameter(cmd, "AppJB", DbType.Boolean, AppJB);
            CreateDataTable(cmd);

        }

        /// <summary>
        /// Delete AppPlist by ID
        /// </summary>
        /// <param name="ID"></param>
        public void VNA_Delete_AppPlist_by_ID(int ID)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Delete_AppPlist_by_ID", true);
            _db.AddParameter(cmd, "ID", DbType.Int32, ID);
            CreateDataTable(cmd);
        }

        /// <summary>
        /// Lay danh sach cac ung dung
        /// </summary>
        /// <returns></returns>
        public DataTable VNA_Select_AppPlist()
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_AppPlist", true);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        /// <summary>
        /// Lay danh sach cac ung dung
        /// </summary>
        /// <param name="Status">Trang thai : Published hoac Testing</param>
        /// <returns></returns>
        public DataTable VNA_Select_AppPlist(bool Status)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_AppPlist_by_Status", true);
            _db.AddParameter(cmd, "Status", DbType.Boolean, Status);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        /// <summary>
        /// Danh sach ung dung testing
        /// </summary>
        /// <param name="Testing"></param>
        /// <returns></returns>
        public DataTable VNA_Select_AppPlist_Testing(bool Testing)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_AppPlist_Testing", true);
            _db.AddParameter(cmd, "Testing", DbType.Boolean, Testing);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }


        /// <summary>
        /// Danh sach ung dung published
        /// </summary>
        /// <param name="Published"></param>
        /// <returns></returns>
        public DataTable VNA_Select_AppPlist_Published(bool Published)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_AppPlist_Published", true);
            _db.AddParameter(cmd, "Published", DbType.Boolean, Published);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        /// <summary>
        /// danh sach ung dung jailbreak hay ko jailbreak
        /// </summary>
        /// <param name="JB">Jailbreak</param>
        /// <param name="Published">Published</param>
        /// <returns></returns>
        public DataTable VNA_Select_AppPlist_JB(bool JB, bool Published)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_AppPlist_JB", true);
            _db.AddParameter(cmd, "JB", DbType.Boolean, JB);
            _db.AddParameter(cmd, "Published", DbType.Boolean, Published);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        /// <summary>
        /// danh sach ung dung jailbreak hay ko jailbreak
        /// </summary>
        /// <param name="JB">Jailbreak</param>
        /// <param name="Published">Published</param>
        /// <param name="AppMode">Phi cong hoac tiep vien</param>
        /// <returns></returns>
        public DataTable VNA_Select_AppPlist_JB_w_AppMode(bool JB, bool Published, int AppMode)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_AppPlist_JB_w_AppMode", true);
            _db.AddParameter(cmd, "JB", DbType.Boolean, JB);
            _db.AddParameter(cmd, "Published", DbType.Boolean, Published);
            _db.AddParameter(cmd, "AppMode", DbType.Int32, AppMode);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        } 


        /// <summary>
        /// Dang nhap de tai ung dung
        /// </summary>
        /// <param name="Username">Ten dang nhap</param>
        /// <param name="Password">Mat khau</param>
        /// <returns></returns>
        public DataTable VNA_LoginDownload(string Username, string Password)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_LoginDownload", true);
            _db.AddParameter(cmd, "Username", DbType.String, Username);
            _db.AddParameter(cmd, "Password", DbType.String, Password);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        /// <summary>
        /// Lay thong tin file theo id
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public DataTable VNA_Select_AppPlist_by_ID(int ID)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_AppPlist_by_ID", true);
            _db.AddParameter(cmd, "ID", DbType.Int32, ID);     
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        /// <summary>
        /// Lay thong tin file theo AppKey
        /// </summary>
        /// <param name="AppKey"></param>
        /// <returns></returns>
        public DataTable VNA_Select_AppPlist_by_AppKey(string AppKey)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_AppPlist_by_AppKey", true);
            _db.AddParameter(cmd, "AppKey", DbType.String, AppKey);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }


        /// <summary>
        /// Kiem tra login tren ung dung
        /// </summary>
        /// <param name="Username"></param>
        /// <param name="Password"></param>
        /// <param name="Udid"></param>
        /// <returns></returns>
        public DataTable VNA_Login_App(string Username, string Password, string Udid)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Login_App", true);
            _db.AddParameter(cmd, "Username", DbType.String, Username);
            _db.AddParameter(cmd, "Password", DbType.String, Password);
            _db.AddParameter(cmd, "Udid", DbType.String, Udid);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        /// <summary>
        /// Them moi user
        /// </summary>
        /// <param name="Username">Ten nguoi dung</param>
        /// <param name="Password">Mat khau</param>
        /// <param name="Udid">Udid</param>
        /// <param name="PartnerCode"></param>
        /// <param name="SupperUser"></param>
        /// <param name="AppMode"></param>
        /// <param name="Actived"></param>
        /// <param name="Disable"></param>
        /// <returns></returns>
        public DataTable VNA_Insert_User(string Username, string Password, string Udid, string PartnerCode, bool SupperUser, int AppMode, bool Actived, bool Disable, string Email)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Insert_User", true);
            _db.AddParameter(cmd, "Username", DbType.String, Username);
            _db.AddParameter(cmd, "Password", DbType.String, Password);
            _db.AddParameter(cmd, "Udid", DbType.String, Udid);
            _db.AddParameter(cmd, "PartnerCode", DbType.String, PartnerCode);
            _db.AddParameter(cmd, "SupperUser", DbType.Boolean, SupperUser);
            _db.AddParameter(cmd, "AppMode", DbType.Int32, AppMode);
            _db.AddParameter(cmd, "Actived", DbType.Boolean, Actived);
            _db.AddParameter(cmd, "Disable", DbType.Boolean, Disable);
            _db.AddParameter(cmd, "Email", DbType.String, Email);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        /// <summary>
        /// Lay danh sach user theo partner code: PartnerCode =0: lay tat, con lai lay theo code
        /// </summary>
        /// <param name="PartnerCode"></param>
        /// <returns></returns>
        public DataTable VNA_Select_User(string PartnerCode)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_User", true);
            _db.AddParameter(cmd, "PartnerCode", DbType.String, PartnerCode);          
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }


        /// <summary>
        /// Lay thong tin user theo username vaf pasrtnercode
        /// </summary>
        /// <param name="Username"></param>
        /// <param name="PartnerCode"></param>
        /// <returns></returns>
        public DataTable VNA_Select_User_by_Username(string Username, string PartnerCode)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_User_by_Username", true);
            _db.AddParameter(cmd, "Username", DbType.String, Username);
            _db.AddParameter(cmd, "PartnerCode", DbType.String, PartnerCode);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        /// <summary>
        /// Update lai thong tin user
        /// </summary>
        /// <param name="Username"></param>
        /// <param name="PartnerCode"></param>
        /// <param name="Password"></param>
        /// <param name="Udid"></param>
        /// <param name="SupperUser"></param>
        /// <param name="AppMode"></param>
        /// <param name="Actived"></param>
        /// <param name="Disable"></param>
        public void VNA_Update_User(string Username, string PartnerCode, string Password, string Udid, bool SupperUser, int AppMode, bool Actived, bool Disable, string Email)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Update_User", true);
            _db.AddParameter(cmd, "Username", DbType.String, Username);
            _db.AddParameter(cmd, "PartnerCode", DbType.String, PartnerCode);
            _db.AddParameter(cmd, "Password", DbType.String, Password);
            _db.AddParameter(cmd, "Udid", DbType.String, Udid);
            _db.AddParameter(cmd, "SupperUser", DbType.String, SupperUser);
            _db.AddParameter(cmd, "AppMode", DbType.Int32, AppMode);
            _db.AddParameter(cmd, "Actived", DbType.Boolean, Actived);
            _db.AddParameter(cmd, "Disable", DbType.Boolean, Disable);
            _db.AddParameter(cmd, "Email", DbType.String, Email);
            CreateDataTable(cmd);
            
        }

        public void VNA_Delete_User(string Username, string PartnerCode)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Delete_User", true);
            _db.AddParameter(cmd, "Username", DbType.String, Username);
            _db.AddParameter(cmd, "PartnerCode", DbType.String, PartnerCode);            
            CreateDataTable(cmd);
        }


        public void VNA_Insert_FTP(string Udid, string PartnerCode, string HostFTP, string PortFTP, string UserFTP, string PassFTP, bool Passive, string Name, int Type)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Insert_FTP", true);
            _db.AddParameter(cmd, "Udid", DbType.String, Udid);
            _db.AddParameter(cmd, "PartnerCode", DbType.String, PartnerCode);
            _db.AddParameter(cmd, "HostFTP", DbType.String, HostFTP);
            _db.AddParameter(cmd, "PortFTP", DbType.String, PortFTP);
            _db.AddParameter(cmd, "UserFTP", DbType.String, UserFTP);
            _db.AddParameter(cmd, "PassFTP", DbType.String, PassFTP);
            _db.AddParameter(cmd, "Passive", DbType.String, Passive);
            _db.AddParameter(cmd, "Name", DbType.String, Name);
            _db.AddParameter(cmd, "Type", DbType.Int32, Type);
            CreateDataTable(cmd);
        }


        public DataTable VNA_Select_FTP(string PartnerCode)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_FTP", true);            
            _db.AddParameter(cmd, "PartnerCode", DbType.String, PartnerCode);
            DataTable dt= CreateDataTable(cmd);
            return dt;
        }

        public DataTable VNA_Select_FTP_by_PartnerCode_Type(string partnerCode, int type)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_FTP_by_PartnerCode_Type", true);
            _db.AddParameter(cmd, "PartnerCode", DbType.String, partnerCode);
            _db.AddParameter(cmd, "Type", DbType.Int32, type);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        public DataTable VNA_Select_Menu(int ID)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_Menu", true);
            _db.AddParameter(cmd, "ID", DbType.Int32, ID);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        public DataTable VNA_Login(string Username, string Password)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Login", true);
            _db.AddParameter(cmd, "Username", DbType.String, Username);
            _db.AddParameter(cmd, "Password", DbType.String, Password);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        public DataTable VNA_Login(string Username, string Password, int AppMode)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Login_by_AppMode", true);
            _db.AddParameter(cmd, "Username", DbType.String, Username);
            _db.AddParameter(cmd, "Password", DbType.String, Password);
            _db.AddParameter(cmd, "AppMode", DbType.Int32, AppMode);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        public DataTable VNA_Select_FTP_by_ID(int ID)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_FTP_by_ID", true);
            _db.AddParameter(cmd, "ID", DbType.Int32, ID);            
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        public void VNA_Delete_FTP(int ID)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Delete_FTP", true);
            _db.AddParameter(cmd, "ID", DbType.Int32, ID);
            CreateDataTable(cmd);
            
        }

        public void VNA_Insert_FTP(string PartnerCode, string HostFTP, string PortFTP, string UserFTP, string PassFTP, 
            bool Passive, string Name, int Type, bool TSL, bool Active)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Insert_FTP", true);
            _db.AddParameter(cmd, "PartnerCode", DbType.String, PartnerCode);
            _db.AddParameter(cmd, "HostFTP", DbType.String, HostFTP);
            _db.AddParameter(cmd, "UserFTP", DbType.String, UserFTP);
            _db.AddParameter(cmd, "PortFTP", DbType.String, PortFTP);
            _db.AddParameter(cmd, "PassFTP", DbType.String, PassFTP);
            _db.AddParameter(cmd, "Passive", DbType.Boolean, Passive);
            _db.AddParameter(cmd, "Name", DbType.String, Name);
            _db.AddParameter(cmd, "Type", DbType.Int32, Type);
            _db.AddParameter(cmd, "TSL", DbType.Boolean, TSL);
            _db.AddParameter(cmd, "Active", DbType.Boolean, Active);
            DataTable dt = CreateDataTable(cmd);
            
        }

        public void VNA_Update_FTP(int ID, string PartnerCode, string HostFTP, string PortFTP, string UserFTP, 
            string PassFTP, bool Passive, string Name, int Type, bool TSL, bool Active)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Update_FTP", true);
            _db.AddParameter(cmd, "ID", DbType.Int32, ID);
            _db.AddParameter(cmd, "PartnerCode", DbType.String, PartnerCode);
            _db.AddParameter(cmd, "HostFTP", DbType.String, HostFTP);
            _db.AddParameter(cmd, "UserFTP", DbType.String, UserFTP);
            _db.AddParameter(cmd, "PortFTP", DbType.String, PortFTP);
            _db.AddParameter(cmd, "PassFTP", DbType.String, PassFTP);
            _db.AddParameter(cmd, "Passive", DbType.Boolean, Passive);
            _db.AddParameter(cmd, "Name", DbType.String, Name);
            _db.AddParameter(cmd, "Type", DbType.Int32, Type);
            _db.AddParameter(cmd, "TSL", DbType.Boolean, TSL);
            _db.AddParameter(cmd, "Active", DbType.Boolean, Active);
            DataTable dt = CreateDataTable(cmd);

        }

        public DataTable VNA_Select_Menu_by_User(string Username)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_Menu_by_User", true);
            _db.AddParameter(cmd, "Username", DbType.String, Username);
            DataTable dt= CreateDataTable(cmd);
            return dt;
        }

        /// <summary>
        /// Lay thong tin menu theo ID
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public DataTable VNA_Select_Menu_by_ID(int ID)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_Menu_by_ID", true);
            _db.AddParameter(cmd, "ID", DbType.Int32, ID);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        /// <summary>
        /// Lay thong tin menu theo danh sach id cach nhau = dau ,
        /// </summary>
        /// <param name="IDs"></param>
        /// <returns></returns>
        public DataTable VNA_Select_Menu_by_ID(string IDs)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_Menu_by_IDs", true);
            _db.AddParameter(cmd, "ID", DbType.String, IDs);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        /// <summary>
        /// Lay ID cac menu ma user duoc quyen truy cap
        /// </summary>
        /// <param name="Username"></param>
        /// <returns></returns>
        public DataTable VNA_Select_User_Menu(string Username)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_User_Menu", true);
            _db.AddParameter(cmd, "Username", DbType.String, Username);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }


        public DataTable VNA_Select_Menu_by_Url(string Url)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_Menu_by_Url", true);
            _db.AddParameter(cmd, "Url", DbType.String, Url);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        public DataTable VNA_Select_MenuChild_by_User(string Username)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_MenuChild_by_User", true);
            _db.AddParameter(cmd, "Username", DbType.String, Username);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        public DataTable VNA_Select_MenuChild_All()
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_MenuChild_All", true);            
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        public DataTable VNA_Select_Menu_Parent()
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_Menu_Parent", true);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        public void VNA_Insert_User_Menu(string Username, string Menu_ID)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Insert_User_Menu", true);
            _db.AddParameter(cmd, "Username", DbType.String, Username);
            _db.AddParameter(cmd, "Menu_ID", DbType.String, Menu_ID);
            CreateDataTable(cmd);            
        }

        public void VNA_Update_User_Menu(string Username, string Menu_ID)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Update_User_Menu", true);
            _db.AddParameter(cmd, "Username", DbType.String, Username);
            _db.AddParameter(cmd, "Menu_ID", DbType.String, Menu_ID);
            CreateDataTable(cmd);
        }

        public void VNA_Insert_Menu(string Name, int ParentID, bool Visible, string Url, int Order, bool AlwaysVisible)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Insert_Menu", true);
            _db.AddParameter(cmd, "Name", DbType.String, Name);
            _db.AddParameter(cmd, "Url", DbType.String, Url);
            _db.AddParameter(cmd, "ParentID", DbType.Int32, ParentID);
            _db.AddParameter(cmd, "Visible", DbType.Boolean, Visible);
            _db.AddParameter(cmd, "AlwaysVisible", DbType.Boolean, AlwaysVisible);
            _db.AddParameter(cmd, "Order", DbType.Int32, Order);
            
            CreateDataTable(cmd);
        }

        public void VNA_Update_Menu(int ID, string Name, int ParentID, bool Visible, string Url, int Order, bool AlwaysVisible)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Update_Menu", true);
            _db.AddParameter(cmd, "Name", DbType.String, Name);
            _db.AddParameter(cmd, "Url", DbType.String, Url);
            _db.AddParameter(cmd, "ParentID", DbType.Int32, ParentID);
            _db.AddParameter(cmd, "Visible", DbType.Boolean, Visible);
            _db.AddParameter(cmd, "AlwaysVisible", DbType.Boolean, AlwaysVisible);
            _db.AddParameter(cmd, "Order", DbType.Int32, Order);
            _db.AddParameter(cmd, "ID", DbType.Int32, ID);
            CreateDataTable(cmd);
        }

        public DataTable VNA_Select_Menu_All()
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_Menu_All", true);          
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        public DataTable VNA_Select_AppMode()
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_AppMode", true);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        public DataTable VNA_Select_AppPlist_By_AppMode(int AppMode)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_AppPlist_By_AppMode", true);
            _db.AddParameter(cmd, "AppMode", DbType.Int32, AppMode);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        public DataTable VNA_Select_DownloadCounter(string PartnerCode)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_DownloadCounter", true);
            _db.AddParameter(cmd, "PartnerCode", DbType.String, PartnerCode);
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        public void VNA_Insert_DownloadCounter(string PartnerCode)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Insert_DownloadCounter", true);
            _db.AddParameter(cmd, "PartnerCode", DbType.String, PartnerCode);
           CreateDataTable(cmd);
           
        }

        public void VNA_Update_DownloadCounter(string PartnerCode, int Counter, int CounterLimit)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Update_DownloadCounter", true);
            _db.AddParameter(cmd, "PartnerCode", DbType.String, PartnerCode);
            _db.AddParameter(cmd, "Counter", DbType.Int32, Counter);
            _db.AddParameter(cmd, "CounterLimit", DbType.Int32, CounterLimit);
            CreateDataTable(cmd);

        }

        #endregion

        public DataTable VNA_Select_Devices_All_by_Email(string email)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_Devices_All_by_Email", true);
            _db.AddParameter(cmd, "Email", DbType.String, email);
           
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        public DataTable VNA_Select_Devices_Blacklist_by_Email(string email)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_Devices_Blacklist_by_Email", true);
            _db.AddParameter(cmd, "Email", DbType.String, email);

            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        public void VNA_Update_Device_Active(int id, bool active)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Update_Device_Active", true);
            _db.AddParameter(cmd, "ID", DbType.Int32, id);
            _db.AddParameter(cmd, "Active", DbType.Boolean, active);
            CreateDataTable(cmd);
            
        }

        public DataTable VNA_Select_DevicesDownload_by_Month(DateTime dateTime)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_DevicesDownload_by_Month", true);
            _db.AddParameter(cmd, "DateTime", DbType.DateTime, dateTime);

            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        public DataTable VNA_Select_LogSync_by_Uuid(string Uuid)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_LogSync_by_Uuid", true);
            _db.AddParameter(cmd, "Uuid", DbType.String, Uuid);

            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        /// <summary>
        /// Lay danh sach cac device da active theo type : 1: theo gioi; 2: ngay; 3: thang; 4: nam
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public DataTable VNA_Report_Device_Active(int type)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Report_Device_Active", true);
            _db.AddParameter(cmd, "ReportType", DbType.Int32, type);

            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        public void VNA_Delete_Blacklist(int id)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Delete_Blacklist", true);
            _db.AddParameter(cmd, "ID", DbType.Int32, id);

            CreateDataTable(cmd);
        }

        public DataTable VNA_Select_Blacklist_by_ID(int id)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_Blacklist_by_ID", true);
            _db.AddParameter(cmd, "ID", DbType.Int32, id);

            return CreateDataTable(cmd);
        }

        public DataTable VNA_Select_Blacklist()
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_Blacklist", true);

            return CreateDataTable(cmd);
        }

        public DataTable VNA_Insert_Blacklist(string appId, string uuid, string note)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Insert_Blacklist", true);
            _db.AddParameter(cmd, "AppID", DbType.String, appId);
            _db.AddParameter(cmd, "Uuid", DbType.String, uuid);
            _db.AddParameter(cmd, "Note", DbType.String, note);

            return CreateDataTable(cmd);
        }

        public DataTable VNA_Select_AppName_by_PartnerCode(string partnerCode)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_AppName_by_PartnerCode", true);
            _db.AddParameter(cmd, "PartnerCode", DbType.String, partnerCode);

            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        /// <summary>
        /// Danh sach cac menu luon hien thi
        /// </summary>
        /// <param name="partnerCode"></param>
        /// <returns></returns>
        public DataTable VNA_Select_Menu_AlwaysVisible()
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_Menu_AlwaysVisible", true);
            
            DataTable dt = CreateDataTable(cmd);
            return dt;
        }

        /// <summary>
        /// Them moi email supper
        /// </summary>
        /// <param name="Email"></param>
        /// <param name="IsCompany"></param>
        public void VNA_Insert_Emails(string Email, bool IsCompany)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Insert_Emails", true);
            _db.AddParameter(cmd, "Email", DbType.String, Email);
            _db.AddParameter(cmd, "IsCompany", DbType.Boolean, IsCompany);
            CreateDataTable(cmd);
        }

        /// <summary>
        /// Xoa Email Supper
        /// </summary>
        /// <param name="ID"></param>
        public void VNA_Delete_Emails(int ID)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Delete_Emails", true);
            _db.AddParameter(cmd, "ID", DbType.Int32, ID);
            CreateDataTable(cmd);
        }


        /// <summary>
        /// Lay thong tin Email supper theo Email
        /// </summary>
        /// <param name="Email"></param>
        /// <returns></returns>
        public DataTable VNA_Select_Emails_by_Email(string Email)
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_Emails_by_Email", true);
            _db.AddParameter(cmd, "Email", DbType.String, Email);
            return CreateDataTable(cmd);
        }

        public DataTable VNA_Select_Emails()
        {
            IDbCommand cmd = _db.CreateCommand("VNA_Select_Emails", true);
       
            return CreateDataTable(cmd);
        }

    }
} // End of namespace



